package com.xquant.marketdata.marketdata.controller;

import com.xquant.common.security.utils.ExcelUtil;
import com.xquant.common.core.web.controller.BaseController;
import com.xquant.common.core.web.page.TableDataInfo;
import com.xquant.common.log.annotation.Log;
import com.xquant.common.log.enums.BusinessType;
import com.xquant.marketdata.marketdata.domain.*;
import com.xquant.marketdata.marketdata.service.TidxService;
import com.xquant.marketdata.utils.CommResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * newCloud
 * \* User: zip.li
 * \* Date: 2022/3/9
 * \* Time: 15:16
 * \* Description: 指数控制层
 * \
 */
@RestController
@RequestMapping("/tidxCtroller")
public class TidxController extends BaseController {
    @Autowired
    private TidxService tidxService;

    /**
     * 查询指数列表
     */
    //@PreAuthorize("@ss.hasPermi('marketdata:equity:index:indexDataInfo:list')")
    @RequestMapping("/queryTidxInfoByPage.action")
    public TableDataInfo list(@RequestParam Map<String, Object> param)
    {

        List<TidxDTO> list = tidxService.selectTidxInfoList(param);
        for (TidxDTO tfndDTO : list) {
            tfndDTO.setInstrument(tfndDTO.getiCode()+ " " +tfndDTO.getaType()+" " +tfndDTO.getmType());
        }
        return getDataTable(list);
    }

    /**
     * 查询指数成分列表
     */
    @PreAuthorize("@ss.hasPermi('marketdata:equity:index:indexDataComp:list')")
    @RequestMapping("/queryTidxComponentInfoByPage.action")
    public TableDataInfo queryTidxComponentInfoByPage(@RequestParam Map<String, Object> param)
    {
        startPage();
        List<TidxComponentDTO> list = tidxService.selectTidxComponentList(param);
        return getDataTable(list);
    }

    /**
     * 查询指数行情列表
     */
    @PreAuthorize("@ss.hasPermi('marketdata:equity:tidx:tidxSeries:list')")
    @RequestMapping("/queryTidxSeriesInfoByPage.action")
    public TableDataInfo queryTidxSeriesInfoByPage(@RequestParam Map<String, Object> param)
    {
        startPage();
        List<TidxSeriesDTO> list = tidxService.selectTidxSeriesList(param);
        return getDataTable(list);
    }

    /**
     * 修改指数行情
     */
    @RequestMapping("/updateTidxSeries.action")
    @PreAuthorize("@ss.hasPermi('marketdata:equity:tidx:tidxSeries:update')")
    public CommResponse updateTidxSeries(@RequestBody TidxSeriesDTO indexFrom)
    {
       tidxService.updateIndexPrice(indexFrom);
        return CommResponse.success();
    }

    /**
     * 导出指数列表
     */
    @PreAuthorize("@ss.hasPermi('marketdata:equity:tidx:tidxInfo:export')")
    @Log(title = "指数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam Map<String, Object> param)
    {
        startPage();
        List<TidxDTO> list = tidxService.selectTidxInfoList(param);
        ExcelUtil<TidxDTO> util = new ExcelUtil<TidxDTO>(TidxDTO.class);
        util.exportExcel(response, list, "指数信息");
    }

    /**
     * 导出指数成分列表
     */
    @PreAuthorize("@ss.hasPermi('marketdata:equity:tidx:tidxComponent:export')")
    @Log(title = "指数成分", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTidxComponent")
    public void exportTidxComponent(HttpServletResponse response, @RequestParam Map<String, Object> param)
    {
        startPage();
        List<TidxComponentDTO> list = tidxService.selectTidxComponentList(param);
        ExcelUtil<TidxComponentDTO> util = new ExcelUtil<TidxComponentDTO>(TidxComponentDTO.class);
        util.exportExcel(response, list, "指数成分信息");
    }

    /**
     * 导出指数行情列表
     */
    @PreAuthorize("@ss.hasPermi('marketdata:equity:tidx:tidxSeries:export')")
    @Log(title = "指数行情", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTidxSeries")
    public void exportTidxSeries(HttpServletResponse response, @RequestParam Map<String, Object> param)
    {
        startPage();
        List<TidxSeriesDTO> list = tidxService.selectTidxSeriesList(param);
        ExcelUtil<TidxSeriesDTO> util = new ExcelUtil<TidxSeriesDTO>(TidxSeriesDTO.class);
        util.exportExcel(response, list, "指数行情信息");
    }

}
